<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane
          :key="item.dictValue"
          v-for="item in warningTypeOptions"
          :label="item.dictLabel"
          :name="item.dictValue"
      >
      </el-tab-pane>
    </el-tabs>
    <uc-table url="admin/warning/getPageData" name="安全预警" ref="warningTable" pageable table-border
              :search-form="searchForm">
      <template slot="searchForm">
        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
          <!--搜索输入框-->
          <el-form-item>
            <el-input type="text" v-model="searchForm.title" placeholder="请输入告警名称" clearable></el-input>
          </el-form-item>
          <el-form-item v-if="enterPriseHidden">
            <el-select v-model="searchForm.enterpriseId" placeholder="请选择主体" clearable @clear="clearInput1">
              <el-option v-for="(item,index) in enterpriseDominantList" :key="index" :value="item.ucId"
                         :label="item.name"></el-option>
            </el-select>
          </el-form-item>
          <!--搜索按钮--新增按钮-->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
            <el-button type="success" icon="el-icon-plus" class="filter-item" @click="handleAdd()">新 增</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template slot="columns">
        <el-table-column prop="title" label="告警名称" align="left"></el-table-column>
        <el-table-column prop="enterpriseName" label="企业名称" align="left" show-overflow-tooltip></el-table-column>
        <!--                <el-table-column prop="node" label="产品ID" align="left" show-overflow-tooltip></el-table-column>-->
        <el-table-column prop="reportTime" label="上报时间" align="left" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.reportTime|dateFormat}}
          </template>
        </el-table-column>
        <el-table-column prop="handlePersonName" label="处理人" align="left" show-overflow-tooltip></el-table-column>
        <el-table-column prop="handleStatus" label="处理状态" align="left" show-overflow-tooltip>
          <template slot-scope="scope">
            {{statusFormat(scope.row)}}
          </template>
        </el-table-column>
<!--        <el-table-column prop="checkStatus" label="审核状态" align="left" show-overflow-tooltip>-->
<!--          <template slot-scope="scope">-->
<!--            {{scope.row.checkStatus?'已审核':'未审核'}}-->
<!--          </template>-->
<!--        </el-table-column>-->
        <!--                <el-table-column prop="devCollectName" label="采集设备" align="left" show-overflow-tooltip></el-table-column>-->
        <el-table-column label="操作" width="240" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </template>
    </uc-table>
  </div>
</template>

<script>
import UcTable from "@/components/UcTable/index.vue";
import {getInEnterpriseDominantList} from "@/api/enterpriseDominant";
import {addData} from "@/api/warning";

export default {
  name: "equipmentList",
  components: {UcTable},
  data() {
    return {
      searchForm: {
        deleted: false,
        type: null
      },
      cameraForm: {
        ucId: ""
      },
      enterpriseDominantList: [],
      warningStatusOptions: [],
      warningTypeOptions: [],
      deleteLoading: false,
      activeName: "01"
    }
  },
  created() {
    this.getDicts("warning_type").then(response => {
      this.warningTypeOptions = response.data.data;
    });
    this.getDicts("warning_handle_status").then(response => {
      this.warningStatusOptions = response.data.data;
    });
    this.getInEnterpriseDominantList()
  },
  computed: {
    enterPriseHidden() {
      let roleCode = this.$store.getters.roleCode;
      return roleCode == "ADMIN" || roleCode == "XT-ADMIN" || roleCode == "ZD-ADMIN" || roleCode == "DD-ADMIN" || roleCode == "JW-ADMIN" || roleCode == "WB-ADMIN"
    }
  },
  methods: {
    handleAdd() {
      addData(this.cameraForm).then(res => {
      }).catch(res => {
      })
    },
    handleClick(val) {
      if (val.name == "") {
        this.searchForm.type = null
      } else {
        this.searchForm.type = val.name
      }
      this.handleSearch()
    },
    statusFormat(row) {
      return this.selectDictLabel(this.warningStatusOptions, row.handleStatus);
    },
    handleInfo(val) {
      this.$router.push("/securityAlarm/warningInfo/" + val.ucId)
    },
    handleSearch() {
      this.$refs.warningTable.getTableData(1)
    },
    clearInput1() {
      //清楚企业下拉框
      this.searchForm.enterpriseId = null
      this.handleSearch()
    },
    getInEnterpriseDominantList() {
      getInEnterpriseDominantList({deleted: false}).then(res => {
        this.enterpriseDominantList = res.data
      }).catch(error => {

      })
    }
  }
}
</script>

<style scoped>

</style>
